package cn.edu.gzhu.workOrderManagement.config;

import cn.edu.gzhu.workOrderManagement.intercepter.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * webMVC配置类
 * @author chen xi
 */
@Configuration
@Slf4j
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private JwtInterceptor jwtInterceptor;
    @Autowired
    private UserManagementInterceptor userManagementInterceptor;
    @Autowired
    private WorkOrderCreateInterceptor workOrderCreateInterceptor;
    @Autowired
    private WorkOrderDeleteInterceptor workOrderDeleteInterceptor;
    @Autowired
    private WorkOrderListInterceptor workOrderListInterceptor;
    @Autowired
    WorkOrderUpdateInterceptor workOrderUpdateInterceptor;
    @Autowired
    FileInterceptor fileInterceptor;
    @Autowired
    WorkOrderRepeatInterceptor workOrderRepeatInterceptor;
    /**
     * 注册自定义拦截器
     * @param registry
     */
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册自定义拦截器...");
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/user/**","/organization/**","/workOrder/**","/file/**")
                .excludePathPatterns("/user/register", "/user/login");

        registry.addInterceptor(userManagementInterceptor).addPathPatterns("/user/**").excludePathPatterns("/user/register","/user/login","/user/list");
        registry.addInterceptor(userManagementInterceptor).addPathPatterns("/organization/**").excludePathPatterns("/organization/list");

        registry.addInterceptor(workOrderCreateInterceptor).addPathPatterns("/workOrder/create");
        registry.addInterceptor(workOrderDeleteInterceptor).addPathPatterns("/workOrder/delete");
        registry.addInterceptor(workOrderListInterceptor).addPathPatterns("/workOrder/list");
        registry.addInterceptor(workOrderUpdateInterceptor).addPathPatterns("/workOrder/update");
        registry.addInterceptor(workOrderRepeatInterceptor).addPathPatterns("/workOrder/repeat");
        registry.addInterceptor(fileInterceptor).addPathPatterns("/file/upload");

    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // Swagger UI 静态资源配置
        registry.addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/")
                .resourceChain(false);
    }

}
